const app = getApp();
var config = app.globalData.config;
const http = require('../../utils/http.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageUrl:config.imageUrl,
    curriculum_name:'',
    semesterList:[],  //学期列表
    semester_index:0,
    semester_id:0,  //学期id
    schoolName:""  //学校名称
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getSchoolData();
  },
  //选择学期
	semesterChange: function(e) {
		let semester_index = e.detail.value; //选中的列表下标
		let semester_id = this.data.studentList[e.detail.value].id;
		this.setData({
      semester_index: semester_index,
      semester_id:semester_id
		});
	},
  getSchoolData(){//获取学校+学期记录
    var that = this;
		http.httpPost(config.getSchoolData, {
		}, function(e) {
			if (e.code == 1) {
        var _data = e.data;
					that.setData({
            schoolName:_data.schoolName,
            semesterList: _data.semesterList,
            semester_id:_data.semesterList[0].id
					});
        
        that.getEnrollList();
			}
		});
  },
  getEnrollList() {
    var that = this;
    var curriculum_name = this.data.curriculum_name; //学生姓名
		http.httpPost(config.getEnrollList, {
      curriculumName: curriculum_name,
      semester_id:that.data.semester_id
		}, function(e) {
			if (e.code == 1) {
				if (e.data != []) {
					that.setData({
						enroll_list: e.data
					});
				} else { //暂无数据
					wx.showToast({
						title: e.msg,
						icon: 'none',
						duration: 3000,
						mask: true
					});
				}

			}
		});
	},
	searchFun(e) {//搜索
    var searchName = e.detail.value;
    console.log(searchName);
		this.setData({
			curriculum_name: searchName
    });
    console.log(this.data.curriculum_name);
		this.getEnrollList();
  },
  clickCurriculum(e){//点击进入详情页
    var curriculum_id = e.currentTarget.dataset.id;	//课程id
    wx.navigateTo({
      url: './stais_detail?curriculum_id='+curriculum_id
    })

  }
})